{% extends 'base.html' %}
{% load static %}

{% block title %}
    良言|注册
{% endblock %}

{% block header_extends %}
    <link rel="stylesheet" href="{% static 'login.css' %}">
{% endblock %}

{% block content %}
<div class="container normal-container">
    <div class="row">
        <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
            {% if not user.is_authenticated %}
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">注册</h3>
                    </div>
                    <div class="panel-body">
                      <form action="" method="POST" id="register_form" autocomplete="on">
                          {% csrf_token %}
                          {% for field in reg_form %}
                              <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                              {{ field }}
                              <p class="text-danger">{{ field.errors.as_text }}</p>
                          {% endfor %}
                          <span class="pull-left text-danger">{{ reg_form.non_field_errors }}</span>
                          <input class="btn btn-primary pull-right" type="submit" value="注册" id="register_btn">
                      </form>
                    </div>
                    <div class="panel-footer">
                        <strong class="text-warning">
                            <p class="text-center">注册后会发送一封邮件到您的注册邮箱，在您通过邮件激活您的账户前，您无法登录</p>
                        </strong>
                    </div>
                </div>
            {% else %}
                <h3>用户已登录，正在跳转到<a href="{% url 'home' %}">首页</a>...</h3>
                <script type="text/javascript">
                    setTimeout("window.location.href = \"{%url 'home' %}\"", 2000);
                </script>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}

{% block script_extends %}
    <script type="text/javascript">
        $("#register_form").submit(function(){
            $("#register_btn").attr({"disabled":"disabled"});
            $("#register_btn").val("请稍后");
        })
    </script>
{% endblock %}